package com.zmn.oms.dubbo.impl.normal.reply;

import com.alibaba.fastjson.JSON;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.oms.common.dio.normal.reply.ReplyQuestionDIO;
import com.zmn.oms.common.dro.normal.reply.ReplyQuestionDRO;
import com.zmn.oms.dubbo.interfaces.normal.reply.ReplyQuestionRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.conf.reply.ReplyQuestion;
import com.zmn.oms.model.entity.conf.reply.ReplyQuestionQuery;
import com.zmn.oms.services.interfaces.conf.reply.ReplyQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 类描述：回访内容查询
 *
 * @author ligang
 * @since 2022/05/30 15:25
 */
@Slf4j
@DubboService(loadbalance = "roundrobin", timeout = 10000, retries = 0, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class ReplyQuestionRemoteServiceImpl implements ReplyQuestionRemoteService {

    @Autowired
    private ReplyQuestionService replyQuestionService;

    @Override
    public ResponseDTO<List<ReplyQuestionDRO>> listReplyQuestionByQuery(ReplyQuestionDIO query) {
        log.info("回访内容查询入参：【{}】", JSON.toJSONString(query));
        try {
            ReplyQuestionQuery questionQuery = BeanMapper.map(query, ReplyQuestionQuery.class);
            List<ReplyQuestion> questionList = replyQuestionService.listByQuery(questionQuery);
            List<ReplyQuestionDRO> dros = BeanMapper.mapList(questionList, ReplyQuestionDRO.class);
            return ResponseDTO.success(dros);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("回访内容查询失败", e);
            return ResponseDTO.fail("回访内容查询失败，请稍后重试");
        }
    }
}
